<%@ page import="com.wwdx.shiro.SessionUser" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/tld/taglib.tld" prefix="p" %>
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <jsp:include page="/public/inc/head.jsp"/>
</head>
<body>
<div id="header" class="navbar navbar-static-top" role="navigation">
    <jsp:include page="/public/inc/top.jsp"/>
</div>
<div class="container-fluid" style="margin-top:5px;margin-bottom:60px;">
    <div class="row">
        <jsp:include page="/public/inc/menu.jsp"/>
        <div class="col-xs-12 col-sm-10">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <div class="media">
                        <div class="media-body">
                            <span class="glyphicon glyphicon-list"></span>分销产品管理
                        </div>
                        <c:if test='<%=SessionUser.getMerchantId() != null && !"".equals(SessionUser.getMerchantId())%>'>
                            <div class="media-right">
                                <a href="/system/wwdx_theme/list" class="btn btn-primary">
                                    <span class="glyphicon glyphicon-plus"></span> 阅读包产品添加
                                </a>
                            </div>
                            <div class="media-right">
                                <a href="/system/wwdx_vip_product/list" class="btn btn-primary">
                                    <span class="glyphicon glyphicon-plus"></span> vip产品添加
                                </a>
                            </div>
                        </c:if>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>商户名称</th>
                            <th>产品名称</th>
                            <th>价格</th>
                            <th>分成比例</th>
                            <th>分成价格</th>
                            <th>商品链接</th>
                            <th>二维码链接</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="l" items="${list}" varStatus="status">
                            <tr>
                                <td>
                                        ${status.count}
                                </td>
                                <td>
                                        ${l.merchantName}
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${l.type eq 2}">
                                            ${l.themeProductName}
                                        </c:when>
                                        <c:otherwise>
                                            ${l.vipProductName}
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${l.type eq 2}">
                                            ￥${l.themePrice}
                                        </c:when>
                                        <c:otherwise>
                                            ￥${l.vipPrice}
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                        ${l.scale}%
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${l.type eq 2}">
                                            ￥${l.themePrice * l.scale / 100}
                                        </c:when>
                                        <c:otherwise>
                                            ￥${l.vipPrice * l.scale / 100}
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <span id="url${status.count}">${l.product_url}</span>
                                    <button class="btn" onclick="copy('url${status.count}')">Copy</button>
                                </td>
                                <td>
                                    <a href="${l.qrcode_url}" target="_blank">二维码链接</a>
                                </td>
                                <td>
                                    <fmt:formatDate value="${l.gmt_created}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                </td>
                                <td>
                                    <a class="btn btn-primary btn-xs" href="/system/wwdx_merchant_product/statistics_list?merchant_id=${l.merchant_id}&product_id=${l.product_id}">
                                        <span class="glyphicon glyphicon-pencil"></span> 查看产品统计
                                    </a>
                                    <shiro:hasRole name="super">
                                        <a class="btn btn-danger btn-xs" onclick="del('${l.id}');">
                                            <span class="glyphicon glyphicon-trash"></span> 删除
                                        </a>
                                    </shiro:hasRole>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
                <div class="panel-footer">
                    <p:pagination url="/system/wwdx_merchant_product/list" total="${listSize}"/>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="/public/inc/bottom.jsp"/>
</body>
</html>
<script type="text/javascript">

    function copy(id){
        new ClipboardJS('.btn', {
            target: function() {
                return document.getElementById(id);
            }
        });
    }

    function del(id) {
        var msg = "您确认要删除吗？";
        if (window.confirm(msg)) {
            window.location.href = "/system/wwdx_merchant_product/del?id=" + id;
        }
    }
</script>